<template>
    <div id="backg">
        <div v-if="has_img">
            <img :src="imgurl" alt="" srcset="" class="postcardimg">
            <p class="tip">长按保存到手机相册</p>
        </div>
        <div v-if="!has_img">
            <p class="tip">暂无明信片图片</p>
        </div>
        <div style="width:300px;margin:0 auto; padding:20px 0;">
          <a target="_blank" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=13020302001048" style="display:inline-block;text-decoration:none;height:20px;line-height:20px;">
            <img src="../assets/countryicon.png" style="float:left;"/><p style="float:left;height:20px;line-height:20px;margin: 0px 0px 0px 5px; color:#939393;">冀公网安备 13020302001048号</p >
          </a >
        </div>
        <a href="https://beian.miit.gov.cn/" target="_blank" rel="noopener noreferrer" style="height:20px;line-height:20px;margin: 0px 0px 0px 5px; color:#939393;">冀ICP备2021009292号-2</a>
    </div>
</template>
<script>
import axios from "axios";
const getpostcard = (params) => {
    return axios.post(`/api/home/user/postcard`, { user_id: window.localStorage.getItem('uid'),open_id:window.localStorage.getItem('openID') });
};
export default {
    data(){
        return{
            has_img:false,
            imgurl:''
        }
    },
    created(){
        let params = new URLSearchParams(location.search);
        var code = params.get('code')
        var fromURL = params.get('fromURL')
        var _this = this;
        if(code){
            var data=axios(
            {
                url:"/api/home/user/openId",
                method:"post",
                data:{
                "uc":code
                },
                contentType:"text",
                processData: false,
                dataType:"text"
            }
            ).then(function (response){
                _this.openID = response.data.data.open_id
                window.localStorage.setItem("openID",_this.openID)
                _this.uid = response.data.data.uid;
                if(_this.uid!=0){//说明已经有信息了
                    window.localStorage.setItem("uid",_this.uid)
                    _this.getPostcardInfo()
                }else{
                    _this.$router.push({name:'login',query:{fromURL:"postcard"}})
                }
            })
        }else if (fromURL) {
            this.getPostcardInfo()
        }
    },
    methods:{
        getPostcardInfo(){
            var _this = this;
            getpostcard().then((res) => {
                _this.imgurl = res.data.data.url;
                if (_this.imgurl) {
                    _this.has_img = true
                }else{
                    _this.has_img = false
                }
            })
        }
    }
}
</script>
<style>
#backg{
    background: url(./../assets/bg.png);
    background-size: 100% 100%;
    height: 100%;
    position: fixed;
    width: 100%;
    overflow: auto;
    display: flex;
    align-items:center;
    justify-content: center;
    flex-direction:column;
}
.tip{
    font-size: 22px;
    font-weight: bold;
}
.postcardimg{
    width: 90%;
    margin: 0 auto;
}
</style>